"""Initial migration

Revision ID: 001
Revises: 
Create Date: 2023-08-01 00:00:00.000000

"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import mysql

# revision identifiers, used by Alembic.
revision = '001'
down_revision = None
branch_labels = None
depends_on = None


def upgrade():
    # 用户表
    op.create_table(
        'sys_users',
        sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
        sa.Column('user_name', sa.String(64), nullable=False, index=True, unique=True),
        sa.Column('real_name', sa.String(64), nullable=True),
        sa.Column('email', sa.String(64), nullable=True),
        sa.Column('role', sa.Integer(), default=0, nullable=True),
        sa.Column('status', sa.Integer(), default=1, nullable=True),
        sa.Column('password', sa.String(255), nullable=False),
        sa.Column('create_by', sa.String(64), nullable=True),
        sa.Column('create_time', sa.DateTime(), nullable=True),
        sa.Column('update_by', sa.String(64), nullable=True),
        sa.Column('update_time', sa.DateTime(), nullable=True),
        sa.Column('version', sa.Integer(), default=1, nullable=True),
        sa.PrimaryKeyConstraint('id')
    )

    # API配置表
    op.create_table(
        'sys_api_config',
        sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
        sa.Column('code', sa.String(50), nullable=False, index=True, unique=True),
        sa.Column('api_url', sa.String(255), nullable=False),
        sa.Column('api_user', sa.String(64), nullable=True),
        sa.Column('api_pwd', sa.String(255), nullable=True),
        sa.Column('api_key', sa.String(255), nullable=True),
        sa.Column('token', sa.String(255), nullable=True),
        sa.Column('remarks', sa.Text(), nullable=True),
        sa.Column('create_by', sa.String(64), nullable=True),
        sa.Column('create_time', sa.DateTime(), nullable=True),
        sa.Column('update_by', sa.String(64), nullable=True),
        sa.Column('update_time', sa.DateTime(), nullable=True),
        sa.Column('version', sa.Integer(), default=1, nullable=True),
        sa.PrimaryKeyConstraint('id')
    )

    # 货物追踪表
    op.create_table(
        'shipment_monitor',
        sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
        sa.Column('number_no', sa.String(50), nullable=False, index=True),
        sa.Column('pickup_warehouse', sa.String(100), nullable=False),
        sa.Column('delivery_warehouse', sa.String(100), nullable=False),
        sa.Column('mac_id', sa.String(50), nullable=False),
        sa.Column('route_data', sa.JSON(), nullable=True),
        sa.Column('create_by', sa.String(64), nullable=True),
        sa.Column('create_time', sa.DateTime(), nullable=True),
        sa.Column('update_by', sa.String(64), nullable=True),
        sa.Column('update_time', sa.DateTime(), nullable=True),
        sa.Column('version', sa.Integer(), default=1, nullable=True),
        sa.PrimaryKeyConstraint('id')
    )


def downgrade():
    op.drop_table('shipment_monitor')
    op.drop_table('sys_api_config')
    op.drop_table('sys_users')